package com.wc.alorithm_blue_bridge_history.littlewhite.Q231209.Q9496;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congege
 * @Description
 *
 * @Date Created in 2023/12/9-19:33
 */
public class Main {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    public static void main(String[] args) {
        int n = nextInt();
        int[] primes = new int[10000];
        long[] pre = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            pre[i] = pre[i - 1] + nextInt();
        }
        mkPrime(primes);
        long ans = -(long) 1e10;
        for (int i = n; i >= 2; i--) {
            for (int prime : primes) {
                if (i - prime >= 0 && i - prime < i) {
                    ans = Math.max(pre[i] - pre[i - prime], ans);
                } else {
                    break;
                }
            }
        }
        System.out.println(ans);
    }

    public static int nextInt() {
        try {
            in.nextToken();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return (int) in.nval;
    }

    public static void mkPrime(int[] primes) {
        int idx = 0;
        for (int i = 1; i <= 100000; i++) {
            if (isPrime(i)) {
                primes[idx++] = i;
            }
        }
    }

    public static boolean isPrime(int num) {
        if (num <= 3) {
            return num > 1;
        }
        if ((num & 1) == 0) {
            return false;
        }
        int sq = (int) Math.sqrt(num);
        for (int i = 2; i <= sq; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
